<?php
/**
 * @author spenceryg
 * @date 2023/4/8
 * @time 9:23 下午
 * @focus love & life
 */


namespace app\api\controller;

use app\common\model\MemberPointsLog;
use hg\apidoc\annotation as Apidoc;

/**
 * Class PointLog
 * @package app\api\controller
 * @Apidoc\Title("积分管理")
 * @Apidoc\Group("api")
 */
class PointLog extends Auth
{

    /**
     * list
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @Apidoc\Title("积分变化列表")
     * @Apidoc\Param("type", desc="1:积分增加 -1：积分消耗 0： 所有")
     */
    public function list()
    {
        $list_rows = input('list_rows', 10, 'intval');
        $where = [];
        $where[] = ['member_id', '=', $this->request->uid];
        $type = input('type', 0, 'intval');
        if($type == 1) {
            $where[] = ['num', '>', 0];
        }
        if($type == -1) {
            $where[] = ['num', '<', 0];
        }

        $res = MemberPointsLog::where($where)->order('id desc')->paginate($list_rows);
        return success('', $res);
    }
}
